package xyz.funnygo.activity;

import xyz.funnygo.base.BaseActivity;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.SaveListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.annotation.view.ViewInject;

public class RegisterActivity extends BaseActivity {

	@ViewInject(id = R.id.register_email)
	private EditText mInputEmail;
	@ViewInject(id = R.id.register_username)
	private EditText mInputUsername;
	@ViewInject(id = R.id.register_password)
	private EditText mInputPassword;
	
	@ViewInject(id = R.id.register_btn_submit, click = "register")
	private Button mButtonSubmit;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.avtivity_register);
	}

	public void register(View v) {
		final BmobUser user = new BmobUser();
		user.setUsername(mInputUsername.getText().toString().trim());
		user.setPassword(mInputPassword.getText().toString().trim());
		user.setEmail(mInputEmail.getText().toString().trim());
		user.signUp(this, new SaveListener() {

			@Override
			public void onSuccess() {
				Intent intent = new Intent(RegisterActivity.this,
						MainActivity.class);
				startActivity(intent);
				finish();
			}

			@Override
			public void onFailure(int code, String msg) {
				Toast.makeText(RegisterActivity.this, "注册失败:" + msg,
						Toast.LENGTH_SHORT).show();
			}
		});
	}
}
